package com.sandeep;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
//import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Servlet implementation class Logindb
 */
public class Logindb extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Logindb() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	    response.setContentType("text/html");  
	    PrintWriter pw=response.getWriter();
	    
	    String Driver="com.mysql.jdbc.Driver";
	    String connectionURL = "jdbc:mysql://localhost:3306/admin"; 
	    Connection connection;
	    
	    try{  
	     
	      String Username = request.getParameter("usn"); 
	      String Password = request.getParameter("psw");
	     
	      
	      Class.forName(Driver);
	      
	      
	      connection = DriverManager.getConnection(connectionURL, "root", "felightrocks"); 
	     
	      PreparedStatement pst = connection.prepareStatement("insert into admin.login values(?, ?)");
	      
	      pst.setString(1, Username);
	      pst.setString(2, Password);
	     
	      int i = pst.executeUpdate();  
	      if(i!=0){  
	        pw.println("<br>Login Successfull");  
	          
	  
	      }  
	      else{  
	        pw.println("Failed to login");  
	       }  
	    }  
	    catch (Exception e){  
	    	System.out.println("Exception : " + e.toString());
	    	 
	    } 
	    
		
				  } 

	}


